package com.itheima.dao.impl;

import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * ClassName:JdbcDaoSupport
 * Package:com.itheima.dao.impl
 * Description:用于抽取dao中重复代码
 * Date:2020/2/27 3:13
 * User: snow
 */
public class JdbcDaoSupport {
	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}


	public void setDataSource(DataSource dataSource) {
		if (jdbcTemplate == null) {
			jdbcTemplate = createJdbcTemplate(dataSource);
		}
	}

	private JdbcTemplate createJdbcTemplate(DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}
}
